package com.wp.admin.controller;

import com.wp.admin.pojo.SysMenu;
import com.wp.admin.service.SysMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author wp
 * @create 2019-03-04 11:24
 */
@RestController
@RequestMapping("menu")
@Api(tags = "菜单控制器")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    @GetMapping("/findTree")
    @ApiOperation(value = "查询菜单树", notes = "根据用户名查询菜单树")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "userName", dataType = "String", required = true, value = "用户名")})
    public ResponseEntity<List<SysMenu>> findTree(@RequestParam String userName) {
        return ResponseEntity.ok(sysMenuService.findTree(userName, 1));
    }

    @GetMapping("/findMenuTree")
    @ApiOperation(value = "查询菜单树", notes = "查询所有菜单树")
    public ResponseEntity<List<SysMenu>> findMenuTree() {
        return ResponseEntity.ok(sysMenuService.findTree(null, 0));
    }
}
